<?php

namespace Portal\Common\Response;

use PhalApi\Response\JsonResponse;

class MyResponse extends JsonResponse
{
    /**
     * @var string $msg 错误返回信息
     */
    protected $code = '00000';
    public function getResult()
    {
        $rs = parent::getResult();

        $rs['code'] = $this->code;
        //代码逻辑中
        //改变code的值
        // $di = \PhalApi\DI();
        // $di->response->setCode('100');
        //判断ret状态码，用于改变code
        if ($this->ret != '200') {
            $this->code = $this->ret;
            $rs['code'] = $this->code;
        }
        $this->setCode($this->code);
        $domain = new \Portal\Domain\Log();
        $domain->insertLog($this->data);
        return $rs;
    }
    public function setCode($code)
    {
        $this->code = $code;
        return $this;
    }
}
